package pers.vic.upload.socket.model;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import pers.vic.upload.constant.CommandEnum;
import pers.vic.upload.constant.ResultEnum;

/**
 * 描述: 文件上传的返回信息
 * @author Vic.xu
 * @date 2022-07-15 10:54
 */
public class SocketResponse {

    /**
     * code :
     * 0 - 表示成功，此时可以查看command 和data
     * 非0 - 表示失败，此时查看msg
     */
    private int code;

    /**错误提示信息*/
    private String msg;

    /**成功时的指令信息*/
    private String command;

    /**成功时候的数据信息*/
    private Object data;

    /**
     *  成功 返回指令
     */
    public static SocketResponse success(CommandEnum commandEnum){
        return new SocketResponse(commandEnum.name());
    }

    /**
     *  成功 返回指令
     */
    public static SocketResponse success(CommandEnum commandEnum, Object data){
        return new SocketResponse(commandEnum.name(), data);
    }

    /**
     * 失败 返回错误提示
     */
    public static SocketResponse error(ResultEnum resultEnum){
        return new SocketResponse(resultEnum.getCode(), resultEnum.getMsg());
    }


    public SocketResponse(String command, Object data) {
        this.command = command;
        this.data = data;
    }

    public SocketResponse(String command) {
        this.command = command;
    }

    public SocketResponse(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public String getCommand() {
        return command;
    }

    public void setCommand(String command) {
        this.command = command;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

}
